package org.trinity.netdisk.util;


public class FileSizeFormatUtil {
    private static final Long BYTE_SIZE = 1L;
    private static final Long KILOBYTE = 1024 * BYTE_SIZE;
    private static final Long MEGABYTE = 1024 * KILOBYTE;
    private static final Long GIGABYTE = 1024 * MEGABYTE;

    public static String fileSizeFormat(Float size) {
        if (size > GIGABYTE) {
            return String.format("%.2f",size / GIGABYTE) +"G";
        }else if (size > MEGABYTE) {
            return String.format("%.2f",size / MEGABYTE) +"M";
        }else if (size > KILOBYTE) {
            return String.format("%.2f",size / KILOBYTE) +"KB";
        }else {
            return size + "b";
        }
    }
}
